import request from '@/utils/axios';
import appName from "../appName"
import constant from '@/utils/constant';

//任务预警个数
export function warnCount(busitype, routeids) {
    return request({
        url: appName.TASK + `/common/task/warnCount?busitype=${busitype}&routeids=${routeids}`,
        method: 'get',
    })
}

//任务超时个数
export function timeOutCount(busitype, routeids) {
    return request({
        url: appName.TASK + `/common/task/timeOutCount?busitype=${busitype}&routeids=${routeids}`,
        method: 'get',
    })
}
//任务超时个数
export function warnOrTimeOutCount(busitype, routeids) {
    return request({
        url: appName.TASK + `/common/task/warnOrTimeOutCount?busitype=${busitype}&routeids=${routeids}`,
        method: 'get',
    })
}
//未完成任务
export function unprocessTotalCount(busitype, routeids) {
    return request({
        url: appName.TASK + `/common/task/unprocessTotalCount?busitype=${busitype}&routeids=${routeids}`,
        method: 'get',
    })
}

//获取节点map
export function getNodeMap() {
    if (window.sessionStorage.getItem("nodeMap")) {
        let obj = JSON.parse(window.sessionStorage.getItem("nodeMap"));
        return new Promise(function (reslove, reject) {
            reslove(obj)  //状态由等待变为成功，传的参数作为then函数中成功函数的实参
        });
    } else {
        return allNode().then(res => {
            if (res.resultCode == constant.SUCCESS && res.data) {
                let map = new Object();
                res.data.list.forEach(item => {
                    map[item.business + "_" + item.routeid] = item;
                });
                window.sessionStorage.setItem("nodeMap", JSON.stringify(map));
                return map;
            }
        }).catch(err => {

        })
    }
}

//所有节点查询
export function allNode() {
    return request({
        url: appName.TASK + `/setting/node/all`,
        method: 'get',
    })
}

//查询所有机构map
export function getSsyOrgMap() {
    if (window.sessionStorage.getItem("ssyorgMap")) {
        let obj = JSON.parse(window.sessionStorage.getItem("ssyorgMap"));
        return new Promise(function (reslove, reject) {
            reslove(obj)  //状态由等待变为成功，传的参数作为then函数中成功函数的实参
        });
    } else {
        return ssyorgReq().then(res => {
            if (res.resultCode == constant.SUCCESS && res.data) {
                window.sessionStorage.setItem("ssyorgMap", JSON.stringify(res.data));
                return res.data;
            }
        }).catch(err => {

        })
    }
}

//查询所有机构map
function ssyorgReq() {
    return request({
        url: appName.TASK + '/common/org/getMap',
        method: 'get',
    })
}

//查询备注列表
export function remarkListReq(taskno,pageSize,pageNumber) {
    return request({
        url: appName.TASK + `/remark/remark/findListByTaskNo`,
        method: 'post',
        data:{
            taskNo:taskno,
            pageSize:pageSize,
            pageNumber:pageNumber,
        }
    })
}

//新增备注信息
export function addRemark(taskno, remark) {
    return request({
        url: appName.TASK + `/remark/remark/addRemark`,
        method: 'post',
        data: {remark: remark, taskNo: taskno}
    })
}

//删除备注信息
export function deleteRemark(id) {
    return request({
        url: appName.TASK + `/remark/remark/deleteById?id=${id}`,
        method: 'get',
    })
}

//任务流转信息查询
export function getChangeList(taskNo) {
    return request({
        url: appName.TASK + `/common/change/list?taskNo=${taskNo}`,
        method: 'get',
    })
}
//任务流转信息查询
export function getChangePage(taskNo,pageSize,pageNumber) {
    return request({
        url: appName.TASK + `/common/change/pageinfo`,
        method: 'post',
        data:{
            taskNo:taskNo,
            pageSize:pageSize,
            pageNumber:pageNumber,
        }
    })
}
//cdfs任务流转信息查询
export function getCdfsChangeList(taskNo,pageSize,pageNumber) {
    return request({
        url: appName.TASK + `/cdfs/change/list`,
        method: 'post',
        data:{
            taskNo:taskNo,
            pageSize:pageSize,
            pageNumber:pageNumber,
        }
    })
}
//获取下一节点
export function getNextNodes(routeid,business) {
    return request({
        url: appName.TASK + `/setting/nodeChange/nextNodes?routeid=${routeid}&business=${business}`,
        method: 'get',
    })
}
//获取cdfs下一节点
export function getCdfsNextNodes(routeid) {
    return request({
        url: appName.TASK + `/cdfs/node/nextNodes?routeid=${routeid}`,
        method: 'get',
    })
}
//任务流转
export function exchangeNode(taskno, routeid) {
    return request({
        url: appName.TASK + `/common/change/exchange`,
        method: 'post',
        data: {routeid: routeid, taskNos: taskno}
    })
}

//加锁
export function lock(taskno) {
    return request({
        url: appName.TASK + `/common/lock/lock`,
        method: 'post',
        data: taskno
    })
}

//解锁
export function unlock(taskno) {
    return request({
        url: appName.TASK + `/common/lock/unlock`,
        method: 'post',
        data:  taskno
    })
}
//强制解锁
export function forceUnlock(taskno) {
    return request({
        url: appName.TASK + `/common/lock/forceUnlock`,
        method: 'post',
        data: taskno
    })
}
//返回原节点
export function taskNodeRollBack(taskno) {
    return request({
        url: appName.TASK + `/common/change/rollback`,
        method: 'post',
        data: taskno
    })
}
//多保单查询
export function morePolicy(policyholderno) {
    return request({
        url: appName.TASK + `/nb/task/morePolicy?policyholderno=${policyholderno}`,
        method: 'get',
    })
}
//任务影像列表查询
export function taskImageList(taskNo,type) {
    return request({
        url: appName.CUSTOMER + `/nb/task/morePolicy?policyholderno=${policyholderno}`,
        method: 'get',
    })
}

//返回权限cdfs code
export function getCdfsAuthCode() {
    return request({
        url: appName.TASK + `/cdfs/auth/getCode`,
        method: 'get',
    })
}
//所有文件类型查询
export function allDocType() {
    return request({
        url: appName.TASK + `/common/doctype/getAllDocType`,
        method: 'get',
    })
}
//获取文件类型
export function getDocTypeMap() {
    if (window.sessionStorage.getItem("docTypeMap")) {
        let obj = JSON.parse(window.sessionStorage.getItem("docTypeMap"));
        return new Promise(function (reslove, reject) {
            reslove(obj)  //状态由等待变为成功，传的参数作为then函数中成功函数的实参
        });
    } else {
        return allDocType().then(res => {
            if (res.resultCode == constant.SUCCESS && res.data) {
                let map = new Object();
                res.data.forEach(item => {
                    map[item.sdoctypeid] = item;
                });
                window.sessionStorage.setItem("docTypeMap", JSON.stringify(map));
                return map;
            }
        }).catch(err => {

        })
    }
}
//获取登录人员的机构信息
export function getInvcoycdes() {
    if (window.sessionStorage.getItem("invcoycdes")) {
        let obj = JSON.parse(window.sessionStorage.getItem("invcoycdes"));
        return new Promise(function (reslove, reject) {
            reslove(obj)  //状态由等待变为成功，传的参数作为then函数中成功函数的实参
        });
    } else {
        return invcoy().then(res => {
            if (res.resultCode == constant.SUCCESS && res.data) {
                let map = new Object();
                res.data.forEach(item => {
                    map[item.sdoctypeid] = item;
                });
                window.sessionStorage.setItem("invcoycdes", JSON.stringify(map));
                return map;
            }
        }).catch(err => {

        })
    }
}
//cdfs加锁
export function cdfsLock(taskno) {
    return request({
        url: appName.TASK + `/cdfs/lock/lock`,
        method: 'post',
        data: taskno
    })
}
//获取当前登录人的机构权限
function invcoy() {
	return request({
	    url: appName.SYSTEM + `/uams/orgnization/corpBaseinfoList`,
	    method: 'post'
	})
}
//cdfs解锁
export function cdfsUnlock(taskno) {
    return request({
        url: appName.TASK + `/cdfs/lock/unlock`,
        method: 'post',
        data:  taskno
    })
}
//cdfs历史任务解锁
export function cdfsHisUnlock(taskno) {
    return request({
        url: appName.TASK + `/cdfs/lock/hisUnlock`,
        method: 'post',
        data:  taskno
    })
}
//cdfs历史任务加锁
export function cdfsHisLock(taskno) {
    return request({
        url: appName.TASK + `/cdfs/lock/hisLock`,
        method: 'post',
        data: taskno
    })
}
//cdfs历史任务流转信息查询
export function getCdfsHisChangeList(taskNo,pageSize,pageNumber) {
    return request({
        url: appName.TASK + `/cdfs/change/hisList`,
        method: 'post',
        data:{
            taskNo:taskNo,
            pageSize:pageSize,
            pageNumber:pageNumber,
        }
    })
}
//查询cdfs备注列表
export function cdfsRemarkListReq(taskno,pageSize,pageNumber) {
    return request({
        url: appName.TASK + `/cdfs/remark/findListByTaskNo`,
        method: 'post',
        data:{
            taskNo:taskno,
            pageSize:pageSize,
            pageNumber:pageNumber,
        }
    })
}

//新增cdfs备注信息
export function addCdfsRemark(taskno, remark) {
    return request({
        url: appName.TASK + `/cdfs/remark/addRemark`,
        method: 'post',
        data: {remark: remark, taskNo: taskno}
    })
}
//查询cdfs历史备注列表
export function cdfsHisRemarkListReq(taskno,pageSize,pageNumber) {
    return request({
        url: appName.TASK + `/cdfs/remark/findHisListByTaskNo`,
        method: 'post',
        data:{
            taskNo:taskno,
            pageSize:pageSize,
            pageNumber:pageNumber,
        }
    })
}

//新增cdfs历史备注信息
export function addCdfsHisRemark(taskno, remark) {
    return request({
        url: appName.TASK + `/cdfs/remark/addHisRemark`,
        method: 'post',
        data: {remark: remark, taskNo: taskno}
    })
}
//cdfs多保单查询
export function findTwoCase(applnum,taskno) {
    return request({
        url: appName.TASK + `/cdfs/twocase/findTwoCase?applnum=${applnum}&taskno=${taskno}`,
        method: 'get',
    })
}
//任务流转
export function cdfsExchangeNode(taskno, routeid) {
    return request({
        url: appName.TASK + `/cdfs/change/exchange`,
        method: 'post',
        data: {routeid: routeid, taskNos: taskno}
    })
}
//CITICGIS综合影响查询 查询功能
export function ImageQuerySearch(searchParams, userId, pageSize, pageNumber){
    return request({
        url: appName.TASK + `/cdfs/image/ImageQueryApi`,
        method: 'post',
        data: {userId: userId, pageSize: pageSize, pageNumber: pageNumber, reqBody:searchParams}
    })
}
//CITICGIS综合影响查询 查看影像信息、查看影像修改记录
export function ImageExtendCheck(params, userId){
    return request({
        url: appName.TASK + `/cdfs/image/ImageExtendApi`,
        method: 'post',
        data: {userId: userId, reqBody:params}
    })
}
//CITICGIS综合影响查询 影像信息——修改imageAlter
export function ImageExtendAlter(params, userId){
    return request({
        url: appName.TASK + `/cdfs/image/ImageProcessApi`,
        method: 'post',
        data: {userId: userId, reqBody:params}
    })
}



//异常样式
export function warnOutSty(row,nodeMap) {
    let sty;
    if (nodeMap && nodeMap[row.busitype + "_" + row.routeid]) {
        if (row.warnFlag == "1") {
            sty = nodeMap[row.busitype + "_" + row.routeid].warnSty;
        } else if (row.warnFlag == "2") {
            sty = nodeMap[row.busitype + "_" + row.routeid].outSty;
        } else {
            sty = ""
        }
    } else {
        sty = ""
    }
    return sty;
}

// 审计日志记录
export function recordLogInfo (params){
    return request({
        url: appName.SCYLOG + '/third/securitylog/record',
        method: 'post',
        data: params,
    })
}

// 直联核保流转记录
export function queryPreUnderTaskRoutingApi(taskno,pageSize,pageNum) {
    return request({
        url: appName.PREUNDER + `/direct/preUnder/queryPreUnderTaskRouting?taskno=${taskno}&pageSize=${pageSize}&pageNum=${pageNum}`,
        method: 'post',
    })
}